
import { v4 as uuid } from 'uuid';
import { ITask } from "../../State/task";
import { State } from "../../";

export interface ICreateTaskOptions {

    /** 模块key */
    moduleKey: string

    /** 任务名称 */
    name?: string;
}

/** 创建任务 */
export async function createTask(s: State, o?: ICreateTaskOptions) {
    if (!o) return;

    const { taskInfo } = s;
    const { moduleKey, name = s.modules[moduleKey].label } = o;

    const newTask: ITask = {
        id: uuid(),
        moduleKey,
        width: 800,
        height: 400,
        name: name,
        x: s.taskInfo.list.length * 20,
        y: s.taskInfo.list.length * 20,
        icon: s.modules[moduleKey].icon,
        zIndex: taskInfo.list.length,
        isZoomX: true,
        isZoomY: true,
        isMinimize: true,
    }

    s.taskInfo.list = [...taskInfo.list, newTask];
}